#pragma once
#include"HashTable.h"

namespace my
{
	template<class K, class V, class Hash = HashFunc<K>>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename hash_bucket::HashTable<K, pair<const K,V>, MapKeyOfT, Hash>::Iterator iterator;
		typedef typename hash_bucket::HashTable<K, pair<const K,V>, MapKeyOfT, Hash>::ConstIterator const_iterator;
		iterator begin()
		{
			return _table.begin();
		}

		iterator end()
		{
			return _table.end();
		}

		const_iterator cbegin() const
		{
			return _table.cbegin();
		}

		const_iterator cend()const
		{
			return _table.cend();
		}

		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return _table.insert(kv);
		}

		iterator find(const K& key)
		{
			return _table.find(key);
		}

		bool erase(const K& key)
		{
			return _table.erase(key);
		}

		V& operator[] (const K& key)
		{
			pair<iterator, bool> ret = _table.insert(make_pair(key, V()));
			return ret.first->second;
		}

	private:
		hash_bucket::HashTable<K, pair<const K,V>, MapKeyOfT, Hash> _table;
	};
}